<template>
  <div class="home">
    <div class="header">
      <div class="location" @click="$router.push({ name: 'Address' })">
        <a-icon type="environment" />
        <span>送至：</span>
        <span v-if="currentAddress==''">塘西</span>
        <span v-else>{{currentAddress}}</span>
        <a-icon type="right" />
      </div>
      <div class="search">
        <!-- <a-input-search placeholder="搜索" enter-button="搜索" /> -->
        <a-input ref="userNameInput" placeholder="搜索" @click="$router.push({name:'Search'})">
          <a-icon slot="prefix" type="search" />
          <a-tooltip slot="suffix">
            <a-button
              type="primary"
              style="border-radius: 20px; background-color: #FF6347"
            >
              搜索
            </a-button>
          </a-tooltip>
        </a-input>
      </div>
    </div>
    <div>
       <a-carousel autoplay class="advertise">
      <div>
        <img src="https://i01piccdn.sogoucdn.com/2cd724e8ea524745" alt="" />
      </div>
      <div>
        <img src="https://i01piccdn.sogoucdn.com/563f3e93a1764d67" alt="" />
      </div>
      <div>
        <img src="https://i03piccdn.sogoucdn.com/b772fc0deef968df" alt="" />
      </div>
    </a-carousel>
    </div>
   

    <div class="nav">
      <div v-for="(item, index) in freshtype" :key="index">
        <img :src="item.img" alt="" />
        <span>{{ item.name }}</span>
      </div>
    </div>

    <div class="banner">
      <div class="banner-title">
        <div class="left">
          <span class="iconfont icon-redu">热销排行榜|大家都在买</span>
        </div>
        <div class="right">
          <a-button
            size="small"
            style="border-radius: 20px"
            @click="$router.push({ name: 'RankList' })"
            ><span>查看更多</span><a-icon type="right" />
          </a-button>
        </div>
      </div>

      <div class="banner-container">
        <div
          class="banner-content"
          v-for="(item, index) in hotproduct"
          :key="index"
        >
          <img :src="item.img" alt="" @click="skip(item.id)" />
          <p>
            <b>{{ item.name }}</b>
          </p>
          <label>{{ item.content }}</label>
          <div>
            <span>￥{{ item.price / 100 }}</span>
            <a-icon type="plus-circle" />
          </div>
        </div>
      </div>
    </div>

    <div class="tab">
      <ul class="ul">
        <li :class="{ active: tabIndex == -1 }" @click="changeTab(-1)">全部</li>
        <li
          @click="changeTab(index)"
          :class="{ active: tabIndex == index }"
          v-for="(item, index) in freshtype"
          :key="index"
        >
          {{ item.name }}
        </li>
      </ul>
    </div>

    <div class="tab-container">
      <div class="tab-content" v-for="(item, index) in freshlist" :key="index">
         
        <img :src="item.img" alt="" @click="skip(item.id)" />
        <p>
          <b>{{ item.name }}</b>
        </p>
        <label class="label1">{{ item.transport }}</label>
        <label class="label2">{{ item.content }}</label>
        <div>
          <span>￥{{ item.price / 100 }}</span>
          <a-icon type="plus-circle" />
        </div>
     
      </div>
     
    </div>
  </div>
</template>

<script>
export default {
  name: "Home",
  data() {
    return {
      freshtype: [], //商品的分类
      tabIndex: -1, //当前的tab索引值
      freshlist: [], //商品列表
    };
  },
  methods: {

    changeTab(index) {
      this.tabIndex = index;

      this.$http
        .get("/work/box-horse/fresh.php", { params: { index: index } })
        .then((res) => {
          this.freshlist = res.data.data;
        })
        .catch((err) => {});
    },
    skip(id) {
      this.$router.push({ name: "Detail", query: { id: id } });
    },
  },
  computed: {
    hotproduct() {
      return this.$store.getters.hotproduct;
    },
    currentAddress() {
      return this.$store.getters.currentAddress;
    },
  },

  mounted() {
    this.$http
      .post("/work/box-horse/freshtype.php")
      .then((res) => {
        this.freshtype = res.data.data;
      })
      .catch((err) => {});

    this.$http
      .post("/work/box-horse/hotlist.php")
      .then((res) => {
        // this.hotproduct = res.data.data;
        this.$store.dispatch("setHotProduct", res.data.data);
      })
      .catch((err) => {});

    this.$http
      .get("/work/box-horse/fresh.php")
      .then((res) => {
        this.freshlist = res.data.data;
      })
      .catch((err) => {});
  },
};
</script>
<style lang="scss">
.home {
  padding-bottom: 55px;
}
.location img {
  width: 13px;
  height: 13px;
  padding: 1px;
}
.search input {
  background-color: #dfedecba;
  border-radius: 20px;
}
.ant-input-affix-wrapper .ant-input-suffix {
  right: 0px;
}
.advertise img {
  width: 100%;
}
.nav img {
  width: 60px;
  height: 60px;
  border-radius: 50%;
}
.nav div {
  display: inline-flex;
  flex-direction: column;
  flex-wrap: wrap;
  width: 20%;
  align-content: center;
}
.nav span {
  color: $font-color;
  font-size: 5px;
  padding: 5px;
}
.banner-title {
  display: flex;
  justify-content: space-between;
  background-color: #FF6347;
  height: 58px;
  border-radius: 10px;
}
.left {
  padding: 13px;
  color: #f5f5f5;
}
.right {
  padding: 13px;
}
.banner-content img {
  width: 80px;
  height: 80px;
}
.banner-content p {
  overflow: hidden;
  text-overflow: ellipsis;
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
  font-size: 5px;
}
.banner-content {
  width: 90px;
  height: 180px;
  padding-left: 5px;
}
.banner-content label {
  overflow: hidden;
  text-overflow: ellipsis;
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 1;
  border-radius: 10px;
  font-size: 3px;
  border: 1px solid #ff9933;
  color: #ff9933;
}
.banner-content span {
  color: #FF6347;
}
.banner-content i {
  float: right;
  font-size: 20px;
}
.banner-container {
  display: flex;
  overflow-y: auto;

  margin-top: -10px;
  border-radius: 10px;
  background-color: #fff;
}
.ul {
  width: 100%;
  padding: 0;
  margin: 0;
  list-style: none;
  overflow: auto;
  //在ios上滚动圆滑
  -webkit-overflow-scrolling: touch;
  white-space: nowrap;
  position: relative;
  padding: 0rem 0.8rem;
  box-sizing: border-box;
  background-color: lightgray;
}
.ul li {
  width: auto;
  height: 100%;
  line-height: 3.5rem;
  margin-right: 0.5rem;
  display: inline-block;
  position: relative;
}
.active {
  color: #FF6347;
  text-decoration: underline;
}
.tab-content img {
  width: 100px;
  height: 100px;
  text-align: center;
}
.tab-content p {
  overflow: hidden;
  text-overflow: ellipsis;
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
  font-size: 5px;
}
.tab-content {
  width: 40%;
  height: 200px;
  margin-top: 10px;
  margin-left: 10px;
  margin-right: 10px;
}
.label1 {
  overflow: hidden;
  text-overflow: ellipsis;
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 1;
  border-radius: 10px;
  font-size: 3px;
  width: 100px;
  border: 1px solid #ff9933;
  color: #ff9933;
}
.label2 {
  font-size: 3px;
  color: rgb(185, 179, 179);
  overflow: hidden;
  text-overflow: ellipsis;
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 1;
}
.tab-content span {
  color: #FF6347;
}
.tab-content i {
  float: right;
  font-size: 20px;
}
.tab-container {
  display: flex;
  border-radius: 10px;
  background-color: #fff;
  flex-wrap: wrap;
  flex-grow: 2;
  justify-content: space-between;
}
/* 轮播图 */
.ant-carousel >>> .slick-slide {
  text-align: center;
  height: 160px;
  line-height: 160px;
  background: #364d79;
  overflow: hidden;
}

.ant-carousel >>> .slick-slide h3 {
  color: #fff;
}
</style>